<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="template.xhtml">
	<ui:define name="content">
		<h:form id="userForm">
			<p:panel id="usersList" header="Users list">
				<p:dataTable var="user" value="#{users.usersList}"
					selection="#{users.selectedUser}">
					<p:column headerText="e-mail" style="width:50%">
						<h:outputText value="#{user.email}"></h:outputText>
					</p:column>
					<p:column headerText="Last timestamp" style="text-align: center; width:35%">
						<h:outputText value="#{user.lastTimestamp}"></h:outputText>
					</p:column>
					<p:column headerText="Mail counter" style="text-align: center; width:10%">
						<h:outputText value="#{user.mailCounter}"></h:outputText>
					</p:column>
					<p:column headerText="Option" style="text-align: center; width:5%">
						<p:commandButton id="deleteButton" process="@this" action="#{users.deleteUser}" 
							icon="ui-icon-close"
							title="Delete" update=":userForm:usersList" style="center">
							<f:setPropertyActionListener value="#{user}"
								target="#{users.selectedUser}" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</p:panel>
		</h:form>
		<br />
		<h:form id="buttonForm">
			<p:panel id="addUser" header="Add user">
				<p:panelGrid columns="2">
					<h:outputLabel for="firstname" value="e-mail address: " />
					<p:inputText id="firstname" value="#{users.newEmail}"
						label="e-mail:" size="40"/>
				</p:panelGrid>
				<br />
				<p:commandButton value="Add" actionListener="#{users.add}"
					update=":userForm:usersList,:buttonForm:addUser" />
			</p:panel>
		</h:form>
	</ui:define>
</ui:composition>
</html>